#include "defines.hpp"

Nave::Nave()
{
    this->x = 0.0f;
    this->y = 0.0f;
    this->z = 0.0f;
}

Nave::Nave(float x, float y, float z){
  this->x = x;
  this->y = y;
  this->z = z;
}

void Nave::Desenha(float x, float y, float z){

   //glScalef(0.5f,0.5f,0.5f);
   glBegin(GL_TRIANGLES);
     //Desenha a nave
       glVertex3f(x+0.15,y,z-0.1);
       glVertex3f(x+0.1,y+0.1,z-0.1);
       glVertex3f(x+0.1,y-0.1,z-0.1);

       glVertex3f(x-0.1,y-0.1,z-0.1);
       glVertex3f(x+0.1,y-0.1,z-0.1);
       glEdgeFlag(FALSE);
       glVertex3f(x+0.1,y+0.1,z-0.1);


       glEdgeFlag(TRUE);
       glVertex3f(x+0.1,y+0.1,z-0.1);
       glVertex3f(x-0.1,y+0.1,z-0.1);
       glEdgeFlag(FALSE);
       glVertex3f(x-0.1,y-0.1,z-0.1);

       glEdgeFlag(TRUE);
       glVertex3f(x-0.1,y+0.1,z-0.1);
       glVertex3f(x-0.15,y,z-0.1);
       glVertex3f(x-0.1,y-0.1,z-0.1);

       glVertex3f(x+0.15,y,z-0.1);
       glVertex3f(x+0.1,y+0.1,z-0.1);
       glVertex3f(x+0.1,y,z+0.1);

       glVertex3f(x+0.15,y,z-0.1);
       glVertex3f(x+0.1,y-0.1,z-0.1);
       glVertex3f(x+0.1,y,z+0.1);

       glVertex3f(x-0.1,y+0.1,z-0.1);
       glVertex3f(x-0.1,y,z+0.1);
       glVertex3f(x-0.15,y,z-0.1);

       glVertex3f(x-0.1,y-0.1,z-0.1);
       glVertex3f(x-0.1,y,z+0.1);
       glVertex3f(x-0.15,y,z-0.1);


       glVertex3f(x-0.1,y+0.1,z-0.1);
       glVertex3f(x+0.1,y+0.1,z-0.1);
       glEdgeFlag(FALSE);
       glVertex3f(x+0.1,y,z+0.1);

       glVertex3f(x-0.1,y+0.1,z-0.1);
       glEdgeFlag(TRUE);
       glVertex3f(x+0.1,y,z+0.1);
       glVertex3f(x-0.1,y,z+0.1);

   glEnd();

   //desenha as coordenadas do objeto no canto superior esquerdo da tela
   tiros1 = (int)tiros.size();
   glRasterPos2f(0.8f, 0.8f);
   std::ostringstream os;
   os<< this->getX()<<" "<<this->getY()<<" "<<this->getZ()<<" "<<this->tiros1;
   Texto::Print_Bitmap_String(GLUT_BITMAP_HELVETICA_18, os.str());
   unsigned int i = 0;
   for (i = 0; i<tiros.size();i++){
      glLineWidth(3.0f);
      tiros.at(i).Desloca(x,y,z);
      CoordProjeteis();
      glLineWidth(1.0f);
   }
}

void Nave::CoordProjeteis (void) {
   glRasterPos2f(0.8f, 0.6f);
   std::ostringstream ofstr;
   unsigned int i = 0;
   for (i=0; i<tiros.size();i++){
     ofstr<< tiros.at(i).GetX() << " " << tiros.at(i).GetY() << " "<< tiros.at(i).GetZ()<<" ";
   }
   Texto::Print_Bitmap_String(GLUT_BITMAP_HELVETICA_18, ofstr.str());
}


void Nave::MoveEsquerda(){
    if (x>-0.8f)
       x = x-0.05f;
}

void Nave::MoveDireita(){
   if (x<0.8f)
     x = x+0.05f;
}

float Nave::getX(){
  return this->x;
}

float Nave::getY(){
  return this->y;
}

float Nave::getZ(){
  return this->z;
}

void Nave::SetX(float novoX){
 x = novoX;
}

void Nave::SetY(float novoY){
 y = novoY;
}

void Nave::SetZ(float novoZ){
 z = novoZ;
}

void Nave::Atira(){
    if ((int)tiros.size() < maxTiros){
      Projetil p = Projetil(x, y-0.1,z+0.1);
      tiros.insert(tiros.end(), p);
      tiros1 =  (int)tiros.size();



      tiros.back().Desloca(x,y,z);
      glutPostRedisplay();
    }
}


Nave::~Nave()
{
    //dtor
}
